home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / NoShitSherlock / NoShitSherlock.c < prev    next >
C/C++ Source or Header  |  2000-06-23  |  3KB  |  114 lines

  1. #include <A4Stuff.h>
  2. #include <Applescript.h>
  3. #include <OSA.h>
  4.  
  5. typedef pascal void (*MaxApplZoneProcPtr)(void);
  6. typedef pascal Boolean (*SystemEventProcPtr)(const EventRecord *);
  7. typedef struct Stub {
  8.     ProcessSerialNumber psn;
  9.     SystemEventProcPtr patch;
  10.     } Stub, **StubHdl;
  11.  
  12. MaxApplZoneProcPtr saveMaxApplZone = 0;
  13. StubHdl stubs = 0;
  14. FSSpec spec;
  15.  
  16. static pascal Boolean MySystemEvent(EventRecord *event) {
  17.     long saveA4 = SetCurrentA4();
  18.     Boolean result = false;
  19.     long i, count;
  20.     Stub stub;
  21.     
  22.     GetCurrentProcess(&stub.psn);
  23.     count = GetHandleSize((Handle) stubs) / sizeof(Stub);
  24.     for(i=0; i<count; i++) {
  25.         if ((stub.psn.highLongOfPSN == (*stubs)[i].psn.highLongOfPSN) &&
  26.             (stub.psn.lowLongOfPSN == (*stubs)[i].psn.lowLongOfPSN)) break;
  27.         }
  28.     
  29.     if (i < count) {
  30.         if ((event->what == keyDown) && 
  31.                 (event->modifiers & cmdKey) &&
  32.                 (event->modifiers & optionKey)) {
  33.              LaunchParamBlockRec pb;
  34.              long i;
  35.              
  36.              result = true;
  37.              event->what = nullEvent;
  38.              
  39.             for(i=0; i<sizeof(pb); ((char *) &pb)[i++] = 0);
  40.              pb.launchBlockID = extendedBlock;
  41.              pb.launchEPBLength = extendedBlockLen;
  42.              pb.launchFileFlags = 0;
  43.              pb.launchControlFlags = launchNoFileFlags | launchContinue;
  44.              pb.launchAppSpec = &spec;
  45.             LaunchApplication(&pb);
  46.              }
  47.           else {
  48.             stub = (*stubs)[i];
  49.             result = (*stub.patch)(event);
  50.             }
  51.         }
  52.     
  53.     SetA4(saveA4);
  54.     return(result);
  55.     }
  56.  
  57. static pascal void MyMaxApplZone() {
  58.     long saveA4 = SetCurrentA4();
  59.     Stub stub;
  60.     
  61.     if (saveMaxApplZone) {
  62.         long i, count;
  63.     
  64.         (*saveMaxApplZone)();
  65.         if (stubs && (*((short *) 0x0910) != 0x0000FFFF)) {
  66.             GetCurrentProcess(&stub.psn);
  67.             stub.patch = 0;
  68.             
  69.             count = GetHandleSize((Handle) stubs) / sizeof(Stub);
  70.             for(i=0; i<count; i++) {
  71.                 if ((stub.psn.highLongOfPSN == (*stubs)[i].psn.highLongOfPSN) &&
  72.                     (stub.psn.lowLongOfPSN == (*stubs)[i].psn.lowLongOfPSN)) break;
  73.                 }
  74.                 
  75.             if (i == count) {
  76.                 SetHandleSize((Handle) stubs, (count+1) * sizeof(Stub));
  77.                 if (!MemError()) {
  78.                     if (stub.patch = (SystemEventProcPtr) NGetTrapAddress(_SystemEvent, ToolTrap)) {
  79.                         NSetTrapAddress((ProcPtr) MySystemEvent, _SystemEvent, ToolTrap);
  80.                         (*stubs)[count] = stub;
  81.                         }
  82.                     }
  83.                 }
  84.             }
  85.         }
  86.     
  87.     SetA4(saveA4);
  88.     }
  89.  
  90. void main() {
  91.     long saveA4 = SetCurrentA4();
  92.     Handle handle = 0;
  93.     FCBPBRec fcbpb;
  94.     long i;
  95.     
  96.     if (stubs = (StubHdl) NewHandleSys(0)) {
  97.         if (handle = Get1Resource('INIT', 0)) {
  98.             DetachResource(handle);
  99.             
  100.             for(i=0; i<sizeof(fcbpb); ((char *) &fcbpb)[i++] = 0);
  101.             fcbpb.ioVRefNum = -1;
  102.             fcbpb.ioRefNum = CurResFile();
  103.             fcbpb.ioNamePtr = spec.name;
  104.             if (!PBGetFCBInfoSync(&fcbpb)) {
  105.                 spec.vRefNum = fcbpb.ioVRefNum;
  106.                 spec.parID = fcbpb.ioFCBParID;
  107.                 }
  108.             
  109.             if (saveMaxApplZone = (MaxApplZoneProcPtr) NGetTrapAddress(_MaxApplZone, OSTrap))
  110.                 NSetTrapAddress((ProcPtr) MyMaxApplZone, _MaxApplZone, OSTrap);
  111.             }
  112.         }
  113.     SetA4(saveA4);
  114.     }